package controller;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class ImageButton extends Object implements ButtonInterface {
    private Image imageSelected;
    private Image imageHover;
    private Image imageIdle;
    private int imageX, imageY;
    private int status;
    private int buttonId;

    private final static int IMAGE_IDLE     = 0;
    private final static int IMAGE_HOVER    = 1;
    private final static int IMAGE_SELECTED = 2;

    public ImageButton(int buttonIdVal,
                       int imageXVal,
                       int imageYVal,
                       Image imageIdleVal,
                       Image imageSelectedVal,
                       Image imageHoverVal) {
        buttonId=buttonIdVal;
        imageX=imageXVal;
        imageY=imageYVal;
        imageIdle=imageIdleVal;
        imageSelected=imageSelectedVal;
        imageHover=imageHoverVal;

        status = IMAGE_IDLE;
    }

    public void paint(Graphics g) {
        Image currentImage=null;
        switch(status) {
            case IMAGE_IDLE:
                currentImage=imageIdle;
                break;
            case IMAGE_HOVER:
                currentImage=imageHover;
                break;
            case IMAGE_SELECTED:
                currentImage=imageSelected;
                status=IMAGE_HOVER;
                break;
            default:
                currentImage=imageIdle;
                break;
        }
        g.drawImage(currentImage, imageX, imageY, 0);
    }

    public void hover() {
        status=IMAGE_HOVER;
    }

    public void idle() {
        status=IMAGE_IDLE;
    }

    public int selected() {
        status=IMAGE_SELECTED;
        return buttonId;
    }
}
